package rexsee.cartoon;

import rexsee.core.utilities.Utilities;
import android.graphics.Rect;

public class Position {

	public final Rect rect = new Rect(0, 0, 100, 100);
	public int z_index = 0;

	public Position parse(String style) {
		if (style == null || style.equals("")) return this;
		style = style.trim();
		if (style.startsWith("(")) style = style.substring(1);
		if (style.endsWith(")")) style = style.substring(0, style.length() - 1);
		String[] argus = style.split(",");
		for (int i = 0; i < argus.length; i++) {
			String value = argus[i].toLowerCase().replace(" ", "").replace("px", "");
			switch (i) {
				case 0 :
					rect.left = Utilities.getInt(value, rect.left);
					break;
				case 1 :
					rect.top = Utilities.getInt(value, rect.top);
					break;
				case 2 :
					rect.right = Utilities.getInt(value, rect.right);
					break;
				case 3 :
					rect.bottom = Utilities.getInt(value, rect.bottom);
					break;
				case 4 :
					z_index = Utilities.getInt(value, z_index);
					break;
				default :
					break;
			}
		}
		return this;
	}

	@Override
	public Position clone() {
		Position rtn = new Position();
		rtn.rect.left = rect.left;
		rtn.rect.right = rect.right;
		rtn.rect.top = rect.top;
		rtn.rect.bottom = rect.bottom;
		rtn.z_index = z_index;
		return rtn;
	}

}
